home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / (A)Z / (A)Z9.ADF / Viacom / oddblit.c < prev    next >
C/C++ Source or Header  |  1987-06-19  |  4KB  |  151 lines

  1. /* :ts=8 bk=0
  2.  *
  3.  * oddblit.c:    Custom blitter routine.  Stolen from Tomas Rokicki's LIFE
  4.  *        program and mashed up beyond all recognition.  Nearly all
  5.  *        comments are Tom's.
  6.  *
  7.  * Leo L. Schwab            8706.4
  8.  */
  9.  
  10. #include <exec/types.h>
  11.  
  12. /*
  13.  *   This include file includes the defines for all the blitter functions.
  14.  *   It only allows use of the `blit' operations; for area fills or line
  15.  *   drawing, it will need to be extended.
  16.  *
  17.  *   Information gleaned from the Hardware Reference Manual.
  18.  */
  19. #define BLTADD (0xdff040L)
  20.  
  21. /*
  22.  *   This structure contains everything we need to know.
  23.  *   Do not do a structure copy into this!  Instead, assign
  24.  *   each field.  The last field assigned must be bltsize; that
  25.  *   starts up the blitter.  Also note that all of these are
  26.  *   write only, and you can't read them.
  27.  */
  28. struct bltstruct {
  29.     short con0;
  30.     short con1;
  31.     short afwm;
  32.     short alwm;
  33.     short *csource, *bsource, *asource, *dsource;
  34.     short bltsize;
  35.     short dmy1, dmy2, dmy3;
  36.     short cmod, bmod, amod, dmod;
  37. } *blitter = BLTADD;
  38.  
  39. /*
  40.  * We need an array which tells what to use for all 256 possible operations.
  41.  */
  42. #define USEA        (0x8)
  43. #define USEB        (0x4)
  44. #define USEC        (0x2)
  45. #define USED        (0x1)
  46.  
  47. char touse[256];
  48. char fwma[16];
  49. char lwma[16];
  50.  
  51. /*
  52.  *   Call initblitdata() once on startup before you ever call oddblit.
  53.  */
  54. initblitdata()
  55. {
  56.     register int i;
  57.     register int s;
  58.  
  59.     for (i=0; i<256; i++) {
  60.         s = USED;
  61.         if ((i >> 4) != (i & 15))
  62.             s += USEA;
  63.         if (((i >> 2) & 51) != (i & 51))
  64.             s += USEB;
  65.         if (((i >> 1) & 85) != (i & 85))
  66.             s += USEC;
  67.         touse[i] = s;
  68.     }
  69.     s = 0xffff;
  70.     for (i=0; i<16; i++) {
  71.         fwma[i] = s;
  72.         s = (s >> 1) & ~0x8000 ;
  73.         lwma[i] = 0xffff - s;
  74.     }
  75. }
  76.  
  77. /*
  78.  * (Tom's original speech:)
  79.  *   This is the major user interface.  Takes addresses and offsets for
  80.  *   all four locations, a modulo and sizes, and a function.
  81.  *   Assumes the modulos for all sources and destination are the same.
  82.  *   You might want to add some arguments or delete some.
  83.  *
  84.  *   All arguments are in pixels (except the addresses and function.)
  85.  *
  86.  *   Before you call this routine, call OwnBlitter(); after you have
  87.  *   called it as many times as you need, call DisownBlitter().  Remember
  88.  *   that you cannot do any printf's or anything else which requires the
  89.  *   blitter when you own the blitter, so be careful with the debug code.
  90.  *   The machine will lock but will not crash.
  91.  */
  92.  
  93. /*
  94.  * Leo here.  This is the bit I mashed to pieces.  Using Tom's BlitLab
  95.  * program (wonderful thing), I figured out what it was I wanted to do.
  96.  * So sit back, relax, and enjoy the narrative to follow...
  97.  *
  98.  * It is assumed that src and dest bitmap are identically sized,
  99.  * and that the noise bitmap is larger than both of them.
  100.  * All x,y parameters are in pixels.
  101.  *
  102.  * Note that this does NOT do a general arbitrary rectangle to rectangle
  103.  * logic function.  It's just a quick hack to OR random bits from one
  104.  * bitplane with another, and place the result into a third location.
  105.  */
  106.  
  107. oddblit (src, dest, sdx, sdy,
  108.      noise, nx, ny,
  109.      xoff, yoff, minterm)
  110. short *src, *dest, *noise;
  111. int sdx, sdy, nx, ny, xoff, yoff;
  112. int minterm;
  113. {
  114.     int noisemod;
  115.  
  116.     /*  Compute width of bitplanes in words  */
  117.     sdx = (sdx + 15) >> 4;
  118.     nx = (nx + 15) >> 4;
  119.  
  120.     /*  noisemod is in bytes  */
  121.     noisemod = (nx - sdx) * 2;
  122.  
  123.     /*  Wait for blitter to finish whatever it may be doing  */
  124.     WaitBlit ();
  125.  
  126.     /*  Start tromping the blitter  */
  127.     blitter -> bsource = src;
  128.     blitter -> dsource = dest;
  129.     blitter -> afwm = blitter -> alwm = 0xffff;
  130.  
  131.     /*  Compute start address into noise plane  */
  132.     blitter -> asource = noise + yoff * nx + (xoff >> 4);
  133.  
  134.     /*  Compute desired shift for noise plane  */
  135.     xoff &= 15;
  136.  
  137.     /*  Comnpute and write control words  */
  138.     blitter -> con0 = (xoff << 12) + (touse[minterm] << 8) + minterm;
  139.     blitter -> con1 = 0;    /*  No shifts on B source or flags  */
  140.  
  141.     /*  Write out the modulos  */
  142.     blitter -> amod = noisemod;
  143.     blitter -> bmod = 0;    /*  These are sized precisely  */
  144.     blitter -> dmod = 0;
  145.  
  146.     /*
  147.      *   This last assignment starts up the blitter.
  148.      */
  149.     blitter->bltsize = (sdy << 6) + sdx;
  150. }
  151.